﻿$(function () {
    var $datagrid = $("#datagrid"), $toolbar = $("#toolbar"), $ticketType = $("#ticketType"), $title = $("#title"),
        $dialog = $("#dialog");
    $("#ticketType").combobox({
        onChange:function(newV,oldV){
            $datagrid.datagrid("reload");
        }
    });

    $datagrid.datagrid({
        singleSelect: true,
        fit: true,
        border: false,
        fitColumns: true,
        url: Constant.ctx("/mulanweb/admin/hot_commodity/search"),
        method: 'post',
        pagination: true,
        toolbar: $toolbar,
        columns: [[
            {field: 'Id', title: '爆款编号'},
            {field: 'TargetId', title: '目标编号'},
            {field: 'AdminId', title: '管理员编号'},
            {field: 'Title', title: '标题'},
            {field: 'Price', title: '单价'},
            {field: 'SalesNumber', title: '销量'},
            {field: 'CreateTime', title: '创建时间'},
            {field: 'HotCommodity', title: '操作', formatter: function (v, r, i) {
                var html = '<a href="#" onclick="saveHot('+r.TargetId+')">取消爆款</a>';
                return html;
            }}
        ]],
        onBeforeLoad: function (param) {
            param.PageNumber = param.page;
            param.PageSize = param.rows;

            var typeId = $("#ticketType").combo('getValue');
            if(typeId){
                param.typeId = typeId;
            }

            return true;
        },
        loadFilter: function (data) {
            var newData = {};
            if (data.ReturnCode == 1) {
                newData.rows = data.DataList;
                if (newData.rows.length > 0) {
                    newData.total = data.TotalRow;
                } else {
                    newData.total = 0;
                }
            }
            return newData;
        }
    });
});





